package com.ymatou.app.api.service;

import java.util.HashMap;
import java.util.Map;

import org.json.JSONObject;

import com.ymt.base.YmatouBaseCall;
import com.ymt.core.tool.Logger;
import com.ymttest.business.YmatouAutoTestCall;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.JsonBeanHelper;
/**
*tokenCall
*FreeMaker Template自动生成代码
*/
public class TokenLoginAuthCall extends YmatouAutoTestCall{
	private static String opurl ="api/User/LoginAuth";
	
	public TokenLoginAuthCall() {
		super(EnvSetup.getSystemUrl("appToken_User"),opurl,"POST","JSON");
	}
	@Override
	public void addDefHeader() {
		client.addHeader("Accept","text/xml,text/javascript,text/html,application/json");
		client.addHeader("Content-Type", "application/json; charset=UTF-8");
	}
	
	
	/**
	 * 获取买家Token
	 * @param sellerid  买家ID
	 * @param password   密码
	 * @return    AccessToken码
	 */
	public static String  getToken(String sellerid , String password) {		
		try {
		 
			Map<String, Object> map = new HashMap<String, Object>();		
			map.put("UserName", sellerid);			    
			map.put("Password", password);
			
		  
			//调用接口json文件
			JSONObject tooken =  JsonBeanHelper.getJsonBean("/com.ymatou.app.api.LoginAuth/LoginAuth/LoginAuthtpl.json");
			tooken = JsonBeanHelper.updateJsonBean(tooken, map); 		
			JSONObject result = new TokenLoginAuthCall().callAndGetReturnData(tooken);     	
			
			String AccessToken =  result.getJSONObject("Data").getString("AccessToken");
			Logger.verifyNotNull(AccessToken, "不为空");
			
			
			return AccessToken;
			
		} catch (Exception e) {
			Logger.fail(e);
		}
		return null;
		
		
	}
	
	
}